package com.example.demo.service.impl;

import com.example.demo.entity.DTO.PetDTO;
import com.example.demo.entity.PetAndUser;
import com.example.demo.mapper.PetAndUserMapper;
import com.example.demo.service.IPetAndUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 宠物与主人中间表 服务实现类
 * </p>
 *
 * @author Mr.sdy
 * @since 2024-06-05
 */
@Service
public class PetAndUserServiceImpl extends ServiceImpl<PetAndUserMapper, PetAndUser> implements IPetAndUserService {
    @Autowired
    private  PetAndUserMapper petAndUserMapper;
    @Override
    public boolean insert(PetAndUser petAndUser) {
        if(petAndUserMapper.insertPU(petAndUser)==1){
            return true;
        }
        return false;
    }

    @Override
    public List<PetDTO> findAllPetsByUserId(Integer userId) {
        if(petAndUserMapper.selectAllPetsByUserId(userId)!=null){
            return petAndUserMapper.selectAllPetsByUserId(userId);
        }
        return null;
    }

    @Override
    public List<PetAndUser> selectByPetIdAndUserId(PetAndUser petAndUser) {
        return petAndUserMapper.selectByPetIdAndUserId(petAndUser);
    }
}
